package tp3.pages.java;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidationError;

import tp1.ObjetoDragonBall;
import tp1.Personaje;

public class CrearPersonajePage extends CrearObjetoDragonBallPage {

	public CrearPersonajePage(PageParameters parameters) {
		Form<ObjetoDragonBall> form = new Form<ObjetoDragonBall>("fp", this.createModel());
		this.add(form);

		form.add(this.getLblNombre());
		form.add(this.getNombre());
		this.getNombre().add(new IValidator<String>() {
			private static final long serialVersionUID = 1L;

			public void validate(IValidatable<String> validatable) {
				if (validatable.getValue().equals("Prueba")) {
					validatable.error(new ValidationError().setMessage("No es un nombre correcto"));
				}
			}
		});
		form.add(this.getNombre());
		form.add(new TextField<Integer>("resistencia"));
		form.add(new Label("lblresistencia", "Resistencia :          "));
		form.add(this.getLblCasillero());
		form.add(this.getCasillero());

		form.add(this.getArchivo());

		this.addActions(form);
		form.add(this.getPanelDeErrores());
	}

	private void addActions(Form<ObjetoDragonBall> form) {
		form.add(this.getBotonGuardar());
	}

	protected CompoundPropertyModel<ObjetoDragonBall> createModel() {
		objetoDragonBall = new Personaje(0, 0);
		return new CompoundPropertyModel<ObjetoDragonBall>(objetoDragonBall);
	}

}
